home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / src / netlib / init_usergroup.c < prev    next >
C/C++ Source or Header  |  1994-09-29  |  4KB  |  146 lines

  1. RCS_ID_C="$Id: init_usergroup.c,v 4.2 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      init_usergroup.c - SAS/C autoinitialization func. for usergroup.library
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/libraries.h>
  12.  
  13. #include <intuition/intuition.h>
  14.  
  15. #include <proto/exec.h>
  16. #include <proto/intuition.h>
  17. #include <dos/dosextens.h>
  18. #include <stdlib.h>
  19.  
  20. #include <libraries/usergroup.h>
  21. #include <clib/usergroup_protos.h>
  22. #include <pragmas/usergroup_pragmas.h>
  23.  
  24. struct Library *UserGroupBase = NULL;
  25.  
  26. #define USERGROUPVERSION 1    /* minimum version to use */
  27.  
  28. extern STRPTR _ProgramName;    /* SAS startup module defines this :-) */
  29. extern int errno;        /* errno variable */
  30.  
  31. /****** net.lib/autoinit_usergroup.library ************************************
  32.  
  33.     NAME
  34.         autoinit usergroup.library - SAS C Autoinitialization Functions
  35.  
  36.     SYNOPSIS
  37.         error = _STI_200_openUserGroup()
  38.  
  39.         LONG _STI_200_openUserGroup(void)
  40.  
  41.         _STD_200_closeUserGroup()
  42.  
  43.         void _STD_200_closeUserGroup(void)
  44.  
  45.     FUNCTION
  46.         These functions open and close the usergroup.library at the startup
  47.         and exit of the program, respectively.  For a program to use these
  48.         functions, it must be linked with netlib:usr.lib.
  49.  
  50.     NOTES
  51.         _STI_200_openUserGroup() also checks that the system version is at
  52.         least 37.  It puts up a requester if the usergroup.library is not
  53.         found or is too old version.
  54.  
  55.         The autoinitialization and autotermination functions are features
  56.         specific to the SAS C6.  However, these functions can be used with
  57.         other (ANSI) C compilers, too.  Example follows:
  58.  
  59.         \* at start of main() *\
  60.  
  61.         atexit(_STD_200_closeUserGroup);
  62.         if (_STI_200_openUserGroup() != 0)
  63.        exit(20);
  64.  
  65.     BUGS 
  66.         The same autoinitialization won't work for both SAS C 6.3 and SAS C
  67.         6.50 or latter.  Only way to terminate an initialization function is
  68.         by exit() call with SAS C 6.3 binary.  If an autoinitialization
  69.         function is terminated by exit() call with SAS C 6.50 binary, the
  70.         autotermination functions won't be called.  Due this braindamage
  71.         these compilers require separate net.lib libraries.
  72.  
  73.     SEE ALSO
  74.         SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  75.         autotermination functions.
  76.  
  77. ****************************************************************************** */
  78.  
  79. /* SAS C 6.50 kludge */
  80. #if __VERSION__ > 6 || __REVISION__ >= 50
  81. #define exit(x) return(x)
  82. #endif
  83.  
  84. /*
  85.  * Using __stdargs prevents creation of register arguments entry point.
  86.  * If both stack args and reg. args entry points are created, this
  87.  * function is called _twice_, which is not wanted.
  88.  */
  89. LONG __stdargs
  90. _STI_200_openUserGroup(void)
  91. {
  92.   const UBYTE *errorStr = "Cannot open %s.";
  93.  
  94.   struct Process *me = (struct Process *)FindTask(NULL);
  95.   /*
  96.    * Check OS version
  97.    */
  98.   if ((*(struct Library **)4)->lib_Version < 37)
  99.     exit(20);
  100.  
  101.   /*
  102.    * Open bsdsocket.library
  103.    */
  104.   if (UserGroupBase = OpenLibrary(USERGROUPNAME, USERGROUPVERSION)) {
  105.     if (ug_SetupContextTags(_ProgramName,
  106.                 UGT_INTRMASK, SIGBREAKB_CTRL_C,
  107.                 UGT_ERRNOPTR(sizeof(errno)), &errno,
  108.                 TAG_END)
  109.     == 0)
  110.       return 0;
  111.     errorStr = "Cannot initialize context in %s.";
  112.   }
  113.  
  114.   /*
  115.    * Post requester only if approved 
  116.    */
  117.   if (me->pr_WindowPtr != (APTR) -1) {
  118.     struct Library *IntuitionBase;
  119.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  120.       struct EasyStruct libraryES;
  121.  
  122.       libraryES.es_StructSize = sizeof(libraryES);
  123.       libraryES.es_Flags = 0;
  124.       libraryES.es_Title = _ProgramName;
  125.       libraryES.es_TextFormat = (STRPTR)errorStr;
  126.       libraryES.es_GadgetFormat = "Exit %s";
  127.       
  128.       EasyRequest(NULL, &libraryES, NULL, 
  129.           USERGROUPNAME, 
  130.           _ProgramName);
  131.  
  132.       CloseLibrary(IntuitionBase);
  133.     }
  134.   }
  135.  
  136.   exit(RETURN_FAIL);
  137. }
  138.  
  139. void __stdargs
  140. _STD_200_closeUserGroup(void)
  141. {
  142.   if (UserGroupBase != NULL) {
  143.     CloseLibrary(UserGroupBase), UserGroupBase = NULL;
  144.   }
  145. }
  146.